package assist.client.gwt.view.ui;

import java.util.Date;

import assist.domain.model.GamesQuery;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Widget;

public class SelectGamesViewImpl  extends Composite implements SelectGamesView
{
    private GamesQuery gamesQuery;
    private Presenter presenter;
    @UiField HasValue<Date> startDateBox;
    @UiField HasValue<Date> endDateBox;
    
    public SelectGamesViewImpl(UiBinder<Widget, SelectGamesViewImpl> uiBinder)
    {
        initWidget(uiBinder.createAndBindUi(this));
    }

    @Override
    public void setPresenter(Presenter presenter)
    {
        this.presenter = presenter;
    }

    @Override
    public void setGamesQuery(GamesQuery gamesQuery)
    {
        this.gamesQuery = gamesQuery;
        this.startDateBox.setValue(gamesQuery.getStart());
        this.endDateBox.setValue(gamesQuery.getEnd());  
    }
    
    @UiHandler("loadGames")
    void onClickLoadGames(ClickEvent e)
    {
        this.gamesQuery.setStart(this.startDateBox.getValue());
        this.gamesQuery.setEnd(this.endDateBox.getValue());
        this.presenter.loadGames();
    }    
    
    @UiHandler("showStatsLink")
    void onClickShowStats(ClickEvent e)
    {
        this.presenter.goToShowStats();
    }
    
    
    @UiHandler("selectStatsLink")
    void onClickSelectStats(ClickEvent e)
    {
        this.presenter.goToSelectStats();
    }
   
}
